home *** CD-ROM | disk | FTP | other *** search
/ BCI NET 2 / BCI NET 2.iso / archives / applications / wp / cedpgp.lha / EncipherPGP.rexx < prev    next >
Encoding:
OS/2 REXX Batch file  |  1980-01-06  |  4.9 KB  |  211 lines

  1. /********************************************************************/
  2. /*                                                                  */
  3. /* EncipherPGP.ced - ARexx macro for use with Cygnus Editor and PGP */
  4. /*                                                                  */
  5. /* Mark a block of text you want to be encrypted using PGP, then    */
  6. /* run this macro to encrypt it wit someone's public key. It works  */
  7. /* similar to builtin rot13 command. (Only MUCH slower).            */
  8. /* This macro was tested to work with Cygnus Editor 2.0 to 3.5.     */
  9. /*                                                                  */
  10. /* This code is in Public Domain under GNU General Public License   */
  11. /*                                                                  */
  12. /* author: Janusz A. Urbanowicz <alex@vm.cc.uni.torun.pl>           */
  13. /*                                                                  */
  14. /********************************************************************/
  15.  
  16. /*
  17.  *                $VER: EncipherPGP.ced 1.2 (31.01.1994)
  18.  */
  19.  
  20. Trace Off
  21.  
  22. Options Results
  23.  
  24. lf = '0A'X
  25. tempfile = 'T:ced$pgp.tmp'
  26. cmdline = ''
  27. cmdn = '-ca'
  28. cmdf = '<'||tempfile||' >'||tempfile||'.asc -fca'
  29. pgpt = 0 /* pgp 'type' 0 = 2.3a, 1 = 2.3a.?, 2 = 2.6<ui> */
  30. scrname = 'CygnusEdScreen'
  31. scrnum = 1
  32. portname = 'rexx_ced'
  33. portnum = 0
  34.  
  35. cmd = ''
  36. scratch = 0
  37. ID = ''
  38.  
  39. status portnumber
  40. portnum = result 
  41. if (portnum ~= 0)&(portnum ~== 'RESULT') Then
  42. Do
  43.     scrnum = scrnum + portnum
  44.     portname = portname||portnum
  45. End
  46.  
  47. scrname = scrname||scrnum
  48.  
  49. Call Close 'STDOUT'        /* Thanx for that goes to Rick Younie*/
  50. Call Close 'STDIN'
  51. Call Open 'STDOUT','CON:16/24/620/130/PGPAmiga Output/CLOSE/WAIT/SCREEN'||scrname
  52. Call Pragma '*','STDOUT'
  53. Call Open 'STDIN','*'
  54.  
  55. Call checkf
  56. pgpt = result
  57. If pgpt > 0 then cmd = cmdf
  58. Else
  59. Do
  60.     cmd = cmdn
  61.     cmdline = tempfile||' '
  62. End
  63.  
  64. Address 'rexx_ced'
  65. If pgpt = 1 Then /* is PGP26_IMPERSONATE option avaliable ? */
  66. Do
  67.     okay2 "Do you want the enciphered packet to be"||lf,
  68.         "in PGP 2.6 format ?"
  69.     If result = 1 Then 
  70.     Do
  71.         okay1 "WARNING: Packet created with this"||lf,
  72.         ||"option set cannot be processed"||lf,
  73.         ||"using 'standard' PGP 2.3a."||lf||lf,
  74.         ||"You SHOULD NOT use this option"
  75.         okay2 "Are you sure you want to use"||lf,
  76.             ||"this option ?"
  77.         If result = 1 Then cmdline = cmdline||' +PGP26_IMPERSONATE=on'
  78.     End
  79. End
  80. Else cmdline = cmdline||' +batchmode=on'
  81.  
  82. If cmd = cmdn Then Call ask
  83.  
  84. cmdline = cmd||' '||cmdline
  85.  
  86. cut block
  87. If result = 1 Then Call encrypt
  88. Else
  89. Do
  90.     okay2 "No area selected."||lf||"Encipher whole file ?"
  91.     If result = 1 Then 
  92.     Do
  93.         'beg of file'
  94.         'mark block'
  95.         'end of file'
  96.         'cut block'
  97.         Call encrypt
  98.     End
  99. End
  100. Call quit
  101.  
  102. encrypt:
  103. Do
  104.     menu 0 6 0 tempfile /* save block to file */
  105.     Address Command
  106.     'PGP '||cmdline 
  107.     If ~Exists(tempfile||'.asc') Then Call wrongpass
  108.     Else
  109.     Do
  110. /* We check if the output file length is 0 what happens if PGP was in -f mode and passphrase was wrong */
  111.         If Open('outf',tempfile||'.asc','R') Then 
  112.         Do
  113.             If Seek('outf',100,'Begin') = 0 Then
  114.             Do
  115.                 If ~Close('outf') Then Nop
  116.                 Call wrongpass
  117.             End
  118.             Else
  119.             Do
  120.                 Address 'rexx_ced'
  121.                 include file tempfile||'.asc'
  122.                 status 21
  123.             End
  124.         End
  125.     End
  126. End
  127. Return
  128.  
  129. wrongpass:
  130. Address 'rexx_ced'
  131. undo
  132. okay1 "Encryption error !"
  133.  
  134. quit:
  135. Address Command
  136. If Exists(tempfile||'.info') Then 'Delete '||tempfile||'.info QUIET'
  137. If Exists(tempfile||'.asc') Then 'Delete '||tempfile||'.asc QUIET'
  138. If Exists(tempfile) Then 'Delete '||tempfile||' QUIET'
  139. If scratch == 1 Then 'Delete env:PGPPASS QUIET'
  140. If ~Close('STDOUT') Then Nop
  141. Exit 0 
  142.  
  143. ask: Procedure Expose scratch lf
  144. Address Command
  145. 'GetEnv >NIL: PGPPASS'
  146. If rc ~= 0 Then
  147. Do
  148.     Address 'rexx_ced'
  149.     okay2 "Your passphrase is not set in PGPPASS variable."||lf||,
  150.     "It must be set temporarily for running PGP".||lf||,
  151.     "Should it be deleted (for higher security) after use ??"
  152.     If result = 1 then scratch = 1
  153.     else scratch = 0
  154.     okay1 'WARNING: Your passphrase will be visible when you type it in.'
  155.     getstring "'  '  'Please enter passphrase.'" 
  156.     pgppass = result
  157.     pgppass = Strip(pgppass,'T')
  158.     Address Command
  159.     'SetEnv PGPPASS '||'"'||pgppass||'"'
  160. End
  161. Return
  162.  
  163. checkf: Procedure 
  164. Address Command
  165. Call getpath
  166. path = result
  167. If path = "" Then Return 0
  168. Else
  169. Do
  170.     'Version >PIPE:PGPVERSION '||path
  171.     If Open('pvers','PIPE:PGPVERSION','R') Then
  172.     Do
  173.         verstring = ReadLN('pvers')
  174.         If Close('pvers') Then Nop
  175.     End
  176.     Parse Var verstring . version
  177.     Select
  178.         When version = '2.6ui' Then Return 2
  179.         When version = '2.3a.5' Then Return 1
  180.         When version = '2.3a.4' Then Return 1
  181.         When version = '2.3a.3' Then Return 1
  182.         Otherwise Return 0
  183.     End
  184. End
  185.  
  186. getpath: procedure
  187. 'Which >PIPE:PGPPATH PGP'
  188. If rc = 0 Then
  189. Do
  190.     If Open('ppath','PIPE:PGPPATH','R') Then
  191.     Do
  192.         path = ReadLN('ppath')
  193.         If ~Close('ppath') Then Nop
  194.         Return path
  195.     End
  196. End
  197. Else
  198. Do
  199.     'GetEnv >PIPE:PGPPATH PGPPATH'
  200.     If rc = 0 Then
  201.     Do
  202.         If Open('ppath','PIPE:PGPPATH','R') Then
  203.         Do
  204.             path = ReadLN('ppath')
  205.             If ~Close('ppath') Then Nop
  206.             path = path||'/PGP'
  207.             Return path
  208.         End
  209.         Else Return ""
  210.     End
  211.